home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / Swf_Player / Lib / movie.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-17  |  3.9 KB  |  172 lines

  1. ////////////////////////////////////////////////////////////
  2. // Flash Plugin and Player
  3. // Copyright (C) 1998,1999 Olivier Debon
  4. // 
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. // 
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. // 
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. // 
  19. ///////////////////////////////////////////////////////////////
  20. //  Author : Olivier Debon  <odebon@club-internet.fr>
  21. //  
  22. #include "movie.h"
  23.  
  24. FlashMovie::FlashMovie() 
  25. {
  26.     gd = NULL;
  27.     sm = NULL;
  28.     getSwf = NULL;
  29.     getUrl = NULL;
  30.     cursorOnOff = NULL;
  31.     buttons_updated = 0;
  32.     scheduledTime.tv_sec = -1;
  33.     cur_focus = NULL;
  34.     lost_over = NULL;
  35.     msPerFrame = 0;
  36.  
  37.     /* mouse handling */
  38.     mouse_active = 0;
  39.     mouse_x = -1;
  40.     mouse_y = -1;
  41.     button_pressed = 0;
  42.     refresh = 1;
  43. }
  44.     
  45. FlashMovie::~FlashMovie() 
  46. {
  47.     CInputScript *n;
  48.  
  49.     while (main != NULL) {
  50.         n = main->next;
  51.         delete main;
  52.         main = n;
  53.     }
  54.  
  55.     if (gd) delete gd;
  56.     if (sm) delete sm;
  57. }
  58.  
  59. int
  60. FlashMovie::processMovie(GraphicDevice *gd, SoundMixer *sm)
  61. {
  62.     CInputScript *script;
  63.     int wakeUp = 0;
  64.  
  65.     if (sm && sm->playSounds()) {
  66.         wakeUp = 1;
  67.     }
  68.     for (script = this->main; script != NULL; script = script->next) {
  69.         if (script->program == NULL) continue;
  70.         if (script->program->nbFrames == 0) continue;
  71.         if (script->program->processMovie(gd,sm)) {
  72.             wakeUp = 1;
  73.         }
  74.     }
  75.     renderMovie();
  76.     return wakeUp;
  77. }
  78.  
  79. int
  80. FlashMovie::handleEvent(GraphicDevice *gd, SoundMixer *sm, FlashEvent *event)
  81. {
  82.     int wakeUp = 0;
  83.  
  84.     if (sm && sm->playSounds()) {
  85.         wakeUp = 1;
  86.     }
  87.     if (this->main == 0) return 0;
  88.     if (this->main->program == 0) return 0;
  89.     if (this->main->program->handleEvent(gd, sm, event)) {
  90.         wakeUp = 1;
  91.     }
  92.     renderMovie();
  93.     return wakeUp;
  94. }
  95.  
  96. /* current focus bigger and translated if needed */
  97. void
  98. FlashMovie::renderFocus()
  99. {
  100.     Rect rect,boundary;
  101.     Matrix mat;
  102.  
  103.     if (mouse_active || !cur_focus) return;
  104.  
  105.     /* rect is the bbox in screen coordinates */
  106.  
  107.         // Compute the bounding box in screen coordinates
  108.         cur_focus->character->getBoundingBox(&boundary,cur_focus);
  109.         mat = (*gd->adjust) * cur_focus->renderMatrix;
  110.         transformBoundingBox(&rect, &mat, &boundary, 1);
  111.  
  112.     gd->drawBox(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
  113. }
  114.  
  115. void 
  116. FlashMovie::renderMovie()
  117. {
  118.     CInputScript *script,*prev,*next;
  119.     Rect clipping;
  120.     Matrix identity;
  121.  
  122.     clipping.reset();
  123.  
  124.     // First pass to update the clipping region
  125.     for (script = this->main; script != NULL; script = script->next) {
  126.         if (script->level == -1) {
  127.             clipping.xmin = -32768;
  128.             clipping.ymin = -32768;
  129.             clipping.xmax =  32767;
  130.             clipping.ymax =  32767;
  131.             continue;
  132.         }
  133.         if (script->program == NULL) continue;
  134.         if (script->program->dl->bbox.xmin == LONG_MAX) continue;
  135.         transformBoundingBox(&clipping, &identity, &script->program->dl->bbox, 0);
  136.         script->program->render = 0;
  137.     }
  138.  
  139.     if (clipping.xmin == LONG_MAX) return;
  140.  
  141.     // Update the clipping region
  142.     gd->updateClippingRegion(&clipping);
  143.     gd->clearCanvas();
  144.  
  145.     // Second pass to render the movie
  146.     for (script = this->main; script != NULL; script = script->next) {
  147.         if (script->level == -1) continue;
  148.         if (script->program == NULL) continue;
  149.         script->program->dl->render(gd);
  150.     }
  151.     renderFocus();
  152.  
  153.     // Final pass to delete some movies
  154.     script = this->main;
  155.     prev = 0;
  156.     while (script != NULL) {
  157.         if (script->level == -1) {
  158.             next = script->next;
  159.             if (prev == 0) {
  160.                 this->main = next;
  161.             } else {
  162.                 prev->next = next;
  163.             }
  164.             delete script;
  165.             script = next;
  166.         } else {
  167.             prev = script;
  168.             script = script->next;
  169.         }
  170.     }
  171. }
  172.